package com.espirit.hr;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.espirit.eap.sa.Employee;
import com.googlecode.cswish.struts.spring.GenericService;

@Service
public class DutyRecordService {

	@Resource
	GenericService genericService;
	
	public EmployeeAccount generateEntityAccount(Employee emp, Integer year, Integer month) {
		EmployeeAccount ea = new EmployeeAccount();
		
		ea.setEmployee(emp);

		Integer deliveryTimes = getDeliveryTimes(emp, year ,month);
		ea.setDeliveryTimes(deliveryTimes);
		
		BigDecimal faultAmounts = getFaultAmounts(emp, year, month);
		ea.setFaultAmount(faultAmounts);
		
		
		List<DutyRecord> dutyRecords = getEmployeeDutyRecords(emp, year, month);
		
		// dutyrecords can fetch.
		ea.setLeaveAppHours(BigDecimal.valueOf(18));
		ea.setOtHours(BigDecimal.valueOf(80));
		
		EmployeeAccountLateItem lateItem = new EmployeeAccountLateItem();
		lateItem.setParent(ea);
		lateItem.setMinutes(6);
		ea.safeLateItems().add(lateItem);
		
		ea = genericService.add(ea);
		return ea;
	}

	//TODO
	private BigDecimal getFaultAmounts(Employee emp, Integer year, Integer month) {
		return null;
	}

	private Integer getDeliveryTimes(Employee emp, Integer year, Integer month) {
		return 0;
	}

	private List<DutyRecord> getEmployeeDutyRecords(Employee emp, Integer year,
			Integer month) {
		return Collections.EMPTY_LIST;
	}
	
}
